package com.ruoyi.web.controller.agriculture;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.agriculture.domain.po.AgEquipment;
import com.ruoyi.system.agriculture.service.IAgEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 农业设备Controller
 */
@RestController
@RequestMapping("/agriculture/equipment")
public class AgEquipmentController extends BaseController {
    @Autowired
    private IAgEquipmentService equipmentService;

    /**
     * 查询农业设备列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgEquipment equipment) {
        startPage();
        List<AgEquipment> list = equipmentService.selectEquipmentList(equipment);
        return getDataTable(list);
    }

    /**
     * 导出农业设备列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:export')")
    @Log(title = "农业设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgEquipment equipment) {
        List<AgEquipment> list = equipmentService.selectEquipmentList(equipment);
        ExcelUtil<AgEquipment> util = new ExcelUtil<>(AgEquipment.class);
        return util.exportExcel(list, "农业设备数据");
    }

    /**
     * 获取农业设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId) {
        return success(equipmentService.getById(equipmentId));
    }

    /**
     * 新增农业设备
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:add')")
    @Log(title = "农业设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgEquipment equipment) {
        return toAjax(equipmentService.save(equipment));
    }

    /**
     * 修改农业设备
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:edit')")
    @Log(title = "农业设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgEquipment equipment) {
        return toAjax(equipmentService.updateById(equipment));
    }

    /**
     * 删除农业设备
     */
    @PreAuthorize("@ss.hasPermi('agriculture:equipment:remove')")
    @Log(title = "农业设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentIds) {
        return toAjax(equipmentService.removeBatchByIds(List.of(equipmentIds)));
    }
} 